<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./../template/WorkspaceTemplate.xhtml">

    <ui:define name="top">

    </ui:define>

    <ui:define name="left">

    </ui:define>

    <ui:define name="right">

    </ui:define>

    <ui:define name="content">
        <style>
            .ui-state-highlight.ui-selected {
                color: blueviolet;
            }
            .ui-commandButton-wizard-selected{
                background-color: #D20005;
                font-weight: bold;
                color: #000000;
            }
            .ui-commandButton-wizard-unselected{
                background-color: #D20005;
                font-weight: bold;
                color: #AFAFAF;
            }
        </style>
        
        <h:form id="salesQuotationConfirmForm" style="font-size: 85%">
            <h2>Create Sales Quotation</h2>
            <br/>
            <p:commandButton styleClass="ui-commandButton-wizard-unselected" value="Step 1: Select Client and Order Items" image="ui-icon ui-icon-circle-triangle-e" />
            <p:commandButton styleClass="ui-commandButton-wizard-unselected" value="Step 2: Enter Shipping Details and Special Discount" image="ui-icon ui-icon-circle-triangle-e"/>
            <p:commandButton styleClass="ui-commandButton-wizard-selected" value="Step 3: Confirm" image="ui-icon ui-icon-circle-triangle-e"/>
            <br/>
            <br/>
            <p:messages showDetail="true" />
            <p:growl id="growl" sticky="true"/>
            <p:panel id="panel1" >
                <h:panelGrid id="panelgrid1" columns="6" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Client ID: "/>
                    <h:outputLabel style="font-weight: bold" value="#{sqManagerBean.salesQuotation.client.clientId}"/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Request for Quotation Id: "/>
                    <h:outputText id="rfqNumber" value="#{sqManagerBean.salesQuotation.rfqNumber}"/>

                    <h:outputLabel style="font-weight: bold" value="Company Name: "/>
                    <h:outputText id="companyName" value="#{sqManagerBean.salesQuotation.client.companyName}" />
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Sales Quotation Number: "/>
                    <h:outputText id="poNumber" value="#{sqManagerBean.salesQuotation.sqNumber}"/>

                    <h:outputLabel style="font-weight: bold" value="Currency: "/>
                    <h:selectOneRadio id="currency" required="true" requiredMessage="Please select one currency" value="#{sqManagerBean.salesQuotation.currency}" disabled="true">
                        <f:selectItem itemLabel="SGD" itemValue="true"/>
                        <f:selectItem itemLabel="USD" itemValue="false"/>
                    </h:selectOneRadio>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                   
                    <h:outputLabel style="font-weight: bold" value="Promotion: " />
                    <h:selectBooleanCheckbox value="#{sqManagerBean.salesQuotation.promotion}" disabled="true"/>
                    
                    <h:outputLabel style="font-weight: bold" value="Sales Quotation Date: "/>
                    <h:outputText id="poDate" value="#{sqManagerBean.salesQuotation.dateStr}"/>

                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Validity Date: "/>
                    <h:outputText id="validityDate" value="#{sqManagerBean.salesQuotation.validityDate}">
                        <f:convertDateTime pattern="MMMM dd, yyyy"/>
                    </h:outputText>

                </h:panelGrid>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Order Items" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Order Items"/> 
                <br/>
                <p:dataTable var="oneIL" value="#{sqManagerBean.salesQuotation.itemLines}">
                    <p:column headerText="Product Type" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.product.productType}" />
                    </p:column>
                    <p:column rendered="#{oneIL.qtyOrderedCase != 0}">
                         <f:facet name="header">
                            Quantity <br/> Ordered Case
                        </f:facet>
                        <h:outputText value="#{oneIL.qtyOrderedCase}" />
                    </p:column>
                    <p:column rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (sqManagerBean.salesQuotation.currency)}">
                        <f:facet name="header">
                            Case Unit <br/> Price (SGD)
                        </f:facet>
                        <h:outputText value="#{oneIL.unitPriceSGD}" />
                    </p:column>
                    <p:column rendered="#{(oneIL.qtyOrderedCase != 0) &amp;&amp; (!sqManagerBean.salesQuotation.currency)}">
                        <f:facet name="header">
                            Case Unit <br/> Price (USD)
                        </f:facet>
                        <h:outputText value="#{oneIL.unitPriceUSD}" />
                    </p:column>
                    <p:column rendered="#{oneIL.qtyOrderedCase != 0}">
                        <f:facet name="header">
                            Member <br/> Discount
                        </f:facet>
                        <h:outputText value="#{oneIL.memberDiscount}" />
                    </p:column>
                    <p:column headerText="Order Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.orderDiscount}" />
                    </p:column>
                    <p:column headerText="Special Discount" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.specialDiscount}" />
                    </p:column>
                    <p:column headerText="Sub-total" rendered="#{oneIL.qtyOrderedCase != 0}">
                        <h:outputText value="#{oneIL.subTotal}">
                            <f:convertNumber type="currency"/>
                        </h:outputText>
                    </p:column>
                </p:dataTable>

                <br/>
                <br/>
                <br/>                
                
                <h:outputText value="Shipping Terms" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Shipping Terms"/>
                <h:panelGrid id="panelgrid2" columns="6" cellpadding="10">
                    <h:outputLabel style="font-weight: bold" value="Freight On Board: "/>
                    <h:selectBooleanCheckbox id="fob" value="#{sqManagerBean.salesQuotation.freightOnBoard}" disabled="true"/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value=""/>
                    <h:outputLabel style="font-weight: bold" value="Shipping Details: "/>
                    <h:selectOneRadio id="shipment" value="#{sqManagerBean.salesQuotation.fullShipment}" disabled ="true">
                        <f:selectItem itemLabel="Full Shipment" itemValue="true"/>
                        <f:selectItem itemLabel="Partial Shipment" itemValue="false"/>
                    </h:selectOneRadio>
                </h:panelGrid>

                <br/>
                <br/>
                <br/>

                <h:outputText value="Delivery Order" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Delivery Order"/> 
                <p:dataTable id="olTable" var="deliveryOrderRow" rowIndexVar="rowIndex" value="#{sqManagerBean.salesQuotation.deliveryOrders}" emptyMessage="No order lines is added to Sales Quotation" style="border-color: transparent; ">  
                    <p:column style="border-color: transparent">
                        <br/>
                        <p:fieldset legend="Delivery Order #{rowIndex + 1}">  

                            <h:panelGrid id="olpanelgrid" columns="2" style="border-color: transparent">
                                <h:outputLabel style="font-weight: bold" value="Requested Lead Time: "/>
                                <h:outputText value="#{deliveryOrderRow.leadTimeTS==null?'No requested lead time':deliveryOrderRow.leadTimeTS}">
                                    <f:convertDateTime pattern="MMMM dd, yyyy"/>
                                </h:outputText>
                                <h:outputLabel style="font-weight: bold" value="Shipping Address: "/>
                                <h:outputText value="#{deliveryOrderRow.shippingAddress.addressLine1}" />
                                <h:outputLabel style="font-weight: bold" value=""/>
                                <h:outputText value="#{deliveryOrderRow.shippingAddress.addressLine2}" />
                                <h:outputLabel style="font-weight: bold" value=""/>
                                <h:outputText value="#{deliveryOrderRow.shippingAddress.city}" />
                                <h:outputLabel style="font-weight: bold" value=""/>
                                <h:outputText value="#{deliveryOrderRow.shippingAddress.stateName}" />
                                <h:outputLabel style="font-weight: bold" value=""/>
                                <h:outputText value="#{deliveryOrderRow.shippingAddress.country}" />
                                <h:outputLabel style="font-weight: bold" value=""/>
                                <h:outputText value="#{deliveryOrderRow.shippingAddress.zipCode}" />
                                <h:outputLabel style="font-weight: bold" value=""/>
                                <h:outputLabel style="font-weight: bold" value=""/>
                                <h:outputLabel style="font-weight: bold" value="Indicative Lead Time"/>
                                <h:outputText value="#{deliveryOrderRow.indicativeLeadTime}"/>
                            </h:panelGrid>
                            <br/>
                            <br/>
                            <p:dataTable id="olilTable" var="il" value="#{deliveryOrderRow.itemLines}" emptyMessage="No products selected">  
                                <p:column rendered="#{il.qtyOrderedCase != 0}">  
                                    <f:facet name="header" >  
                                        Item Name
                                    </f:facet>  
                                    <h:outputText value="#{il.product.productType}" />  
                                </p:column>
                                <p:column rendered="#{il.qtyOrderedCase != 0}">
                                    <f:facet name="header">
                                        Quantity Ordered 
                                        <br />
                                        Case
                                    </f:facet>
                                    <h:outputText value="#{il.qtyOrderedCase}" />
                                </p:column>
                            </p:dataTable>
                            <br/>
                        </p:fieldset>
                        <br/>
                    </p:column>
                </p:dataTable>

                <br/>
                <br/>
                <h:outputText value="Comments" style="font-weight: bold; font-size: 110%"/>
                <p:separator title="Comments"/> 
                <h:panelGrid id="panelgrid4" columns="6" cellpadding="10">
                    <h:outputText style="width:670px; height:70px;" value="#{sqManagerBean.salesQuotation.comments}"/><br/>
                </h:panelGrid>

                <br/>
                <br/>
                <p:separator style="height:1px; border-color: #000000; color: #000000; background-color: #000000; outline-color: #000000"/> 
                <div align="right">
                    <h3>
                        <h:panelGrid columns ="2" cellpadding="2" style="text-align: right">
                            <h:outputLabel style="font-weight: bold" value="Sub-total: "/>
                            <h:outputText value="#{sqManagerBean.salesQuotation.subtotal}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Order Discount: "/>
                            <h:outputText value="#{sqManagerBean.salesQuotation.orderDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Member Discount: "/>
                            <h:outputText value="#{sqManagerBean.salesQuotation.memberDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                            <h:outputLabel style="font-weight: bold" value="Special Discount: "/>
                            <h:outputText value="#{sqManagerBean.salesQuotation.specialDiscount}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h3>
                    <h2>
                        <h:panelGrid columns ="2" cellpadding="10">
                            <h:outputLabel for="total" style="font-weight: bold" value="Total: "/>
                            <h:outputText id="total" value="#{sqManagerBean.salesQuotation.total}">
                                <f:convertNumber type="currency" />
                            </h:outputText>
                        </h:panelGrid>
                    </h2>
                </div>

            </p:panel>

            <br/>
            <br/>
            <div align="right">
                <p:commandButton id="cancelSQ" value="Cancel Sales Quotation" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="cancellation"/>
                <p:commandButton id="confirmSQ" value="Save Sales Quotation" ajax="false" action="#{sqManagerBean.confirmSalesQuotation}" image="ui-icon ui-icon-disk" />
            </div>
            <br/>
            <br/>
        </h:form>

        <p:confirmDialog message="Are you sure about cancelling the sales quotation?" width="200"  
                         showEffect="explode" hideEffect="explode"  
                         header="Initiating cancellation" severity="alert" widgetVar="confirmation">
            <h:form id="confirmDialog">
                <p:commandButton value="Yes" update="growl" action="#{sqManagerBean.cancelSalesQuotation}" oncomplete="confirmation.hide()"/>  
                <p:commandButton value="No" onclick="confirmation.hide()" type="button" />
            </h:form>
        </p:confirmDialog>



    </ui:define>

    <ui:define name="bottom">

    </ui:define>

</ui:composition>